package com.blb.edusearchservice.controller;

import com.blb.common.entity.Course;
import com.blb.common.entity.PageEntity;
import com.blb.common.util.ResponseResult;
import com.blb.edusearchservice.service.CourseIndexService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Slf4j
@RestController
public class CourseIndexController {

    @Autowired
    private CourseIndexService courseIndexService;

    /**
     * 初始化课程索引
     * @return
     */
    @GetMapping("/search-courses/init")
    public ResponseResult<String> initIndex(){
        courseIndexService.initCourseIndex();
        return ResponseResult.ok("ok");
    }

    @RequestMapping("search-courses")
    public ResponseResult<PageEntity<Course>> searchCoursePage(@RequestBody Map<String,String> args){
        PageEntity<Course> page = courseIndexService.searchCoursePage(args);
        log.info("search-courses args:{} page:{}",page);
        return ResponseResult.ok(page);
    }

}
